﻿
using HBase;
using hCommand;
using Persistence;
using System.Collections.Generic;

namespace Controller {

    public class CacheSyncTask : ZtTask {
        ISysAuthorityServer authorityServer = WMSDalFactray.getDal<ISysAuthorityServer>();

        protected override bool onlyOneTimeAsync() {
            time = 300;
            return true;
        }

        public override bool excute() {
            if (MyCache.isDirty<DictRes>()) {
                updateDict();
                MyCache.clearDirty<DictRes>();
            }

            if (MyCache.isDirty<SysUser>()) {
                updateUser();
                MyCache.clearDirty<SysUser>();
            }
            check<BParam>();
            check<CoreItem>();
            return true;
        }

        void check<T>() where T : class, CacheData {
            if (MyCache.isDirty<T>()) {
                List<T> list = authorityServer.GetAll<T>();
                MyCache.addOver(list);
                MyCache.clearDirty<T>();
            }

        } 
        void updateDict() {
            var dicts = authorityServer.GetDicts();
            MyCache.addOver(dicts);
        }

        void updateUser() {
            List<SysUser> list = authorityServer.getAll<SysUser>("Sys_User", null, null, " Code ");
            MyCache.addOver(list);
        }
         
    }
}
